/**
 * Copyright (c) 2010 Axa Holding Belgium, SA. All rights reserved.
 * This software is the confidential and proprietary information of the AXA Group.
 */
package chabernac.io;

import java.io.IOException;
import java.io.OutputStream;

import chabernac.tools.ArrayTools;


public class CachingOutputStream extends OutputStream{

  private OutputStream myOutputStream = null;
  private byte[] myCache = new byte[1024];
  private int myCounter = 0;
  
  public CachingOutputStream(OutputStream anOutputStream){
    myOutputStream = anOutputStream;
  }

  @Override
  public void write( int aByte ) throws IOException {
    myOutputStream.write(aByte);
    myCache[myCounter] = (byte)aByte;
    myCounter++;
    if(myCounter == myCache.length){
      myCache = ArrayTools.arrayGrow( myCache, 1024 );
    }
  }
  
  public byte[] getCache(){
    return ArrayTools.trim( myCache, myCounter );
  }

}
